package com.starblink.search.result.ui.cell

import android.view.Gravity
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.starblink.android.basic.adapter.BaseVH
import com.starblink.android.basic.ext.color
import com.starblink.android.basic.extension.dp2px
import com.starblink.android.basic.util.FontUtil
import com.starblink.basic.style.view.empty.SkEmptyView
import com.starblink.search.result.repository.model.GoodsRecommendTileModel
import com.starblink.search.result.repository.model.GoodsResultEmptyModel


class GoodsEmptyCell(parent: ViewGroup) :
    BaseVH<GoodsResultEmptyModel>(SkEmptyView(parent.context).apply {
        layoutParams = StaggeredGridLayoutManager.LayoutParams(
            StaggeredGridLayoutManager.LayoutParams.MATCH_PARENT,
            StaggeredGridLayoutManager.LayoutParams.WRAP_CONTENT
        ).apply {
            isFullSpan = true
        }
    }) {

    private val emptyView = itemView as SkEmptyView

    override fun onBind(model: GoodsResultEmptyModel, position: Int) {
        emptyView.setPadding(emptyView.paddingLeft, 40.dp2px(), emptyView.paddingRight, 20.dp2px())
        emptyView.hideText2 = false
        emptyView.text2 = model.emptyTxt2

        model.emptyTxt1?.takeIf { it.isNotEmpty() }?.let {
            emptyView.text1 = model.emptyTxt1
        }
    }

}

class GoodsTitleCell(parent: ViewGroup) :
    BaseVH<GoodsRecommendTileModel>(TextView(parent.context).apply {
        layoutParams = StaggeredGridLayoutManager.LayoutParams(
            StaggeredGridLayoutManager.LayoutParams.MATCH_PARENT,
            StaggeredGridLayoutManager.LayoutParams.WRAP_CONTENT
        ).apply {
            isFullSpan = true
        }
    }) {

    private val textView = itemView as TextView

    init {
        FontUtil.setKlarna(textView)
        textView.gravity = Gravity.LEFT
        textView.setTextColor(color(com.starblink.basic.style.R.color.gu_text_primary))
        textView.setPadding(12.dp2px(), 20.dp2px(), 0, 0)
        textView.textSize = 18f
    }

    override fun onBind(model: GoodsRecommendTileModel, position: Int) {
        textView.text = model.text

    }

}